﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SlamDunk.MES.Domain.Entities.ResourceContext;

namespace SlamDunk.MES.Repository.EntityConfigurations.ResourceContext
{
    /// <summary>
    /// 设备实体映射配置
    /// </summary>
    public class EquipmentConfig : IEntityTypeConfiguration<Equipment>
    {
        /// <summary>
        /// 配置
        /// </summary>
        public void Configure(EntityTypeBuilder<Equipment> builder)
        {
            //配置属性
            builder.HasKey(equipment => equipment.Id).IsClustered(false);
            builder.HasMany(equipment => equipment.RelatedClasses).WithOne(rel => rel.Equipment).IsRequired().OnDelete(DeleteBehavior.Cascade);
            builder.Property(equipment => equipment.Number).IsRequired().HasMaxLength(32);

            //配置索引
            builder.HasIndex(equipment => equipment.AddedTime).IsUnique(false).IsClustered();
            builder.HasIndex(equipment => equipment.Number).IsUnique();
        }
    }
}
